package helper.request.usermgmt;

import server.dbconnector.DatabaseConnector;
import base.User;
import helper.request.RequestAfterLogin;
import helper.response.AdminandSearchResponse;

import java.sql.*;
import java.util.*;

public class AdminRequest implements RequestAfterLogin {
	private static final long serialVersionUID = -5951817418970155781L;
	private ArrayList<User> users = new ArrayList<User>();

	public AdminRequest() {

	}

	@Override
	public boolean execute() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public User getcurrentuser() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int getcurrentuserid() {
		// TODO Auto-generated method stub
		return 0;
	}
	@Override
	public void process(DatabaseConnector dc) throws SQLException {
		ResultSet rs = dc.query("select * from user where Approved=1");
		if (rs.first()) {
			while (true) {
				int ispub = rs.getInt(10);
				boolean ispubb = false;
				if (ispub == 1)
					ispubb = true;
				User curr=new User(rs.getInt(1), rs.getString(2), rs
						.getString(3), rs.getString(4), rs.getInt(5), rs
						.getString(6), rs.getString(7), ispubb);
				if(rs.getInt(9)==1)curr.setAdmin(true);
				users.add(curr);
				if (!rs.next())
					break;
			}
		}
	}

	public AdminandSearchResponse process(DatabaseConnector dc, int empty)
			throws SQLException {
		process(dc);
		AdminandSearchResponse asr = new AdminandSearchResponse(users);
		return asr;
	}
}
